How to call memcmp() on two parts of byte[] (with offset)?

Posted by brickner on Stack Overflow See other posts from Stack Overflow or by brickner
Published on 2010-06-08T19:58:16Z Indexed on 2010/06/09 2:52 UTC
Read the original article Hit count: 266

Filed under:
|
|
|
|

Hi,

I want to compare parts of byte[] efficiently - so I understand memcmp() should be used.

I know I can using PInvoke to call memcmp() - http://stackoverflow.com/questions/43289/comparing-two-byte-arrays-in-net

But, I want to compare only parts of the byte[] - using offset, and there is no memcmp() with offset since it uses pointers.

int CompareBuffers(byte[] buffer1, int offset1, byte[] buffer2, int offset2, int count)
{
  // Somehow call memcmp(&buffer1+offset1, &buffer2+offset2, count)
}

Should I use C++/CLI to do that?

Should I use PInvoke with IntPtr? How?

Thank you.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET